//此文件为管理用户信息的仓库
import { defineStore } from 'pinia'
import { staticRoutes} from '@/routers/modules/staticRouter'
import piniaPersistConfig from "@/stores/config";
import type { userInfoReponseData } from '@/api/modules/login'
import type{ UserInfoState} from "@/stores/interface";
// 存储用户信息，并持久化，用户信息不像权限数据一样重要，所以采用本地存储，节省流量
export const useUserInfoStore = defineStore({
  id: "xianda-user",
  state: (): UserInfoState => ({
    // 登录成功后的用户 token
    token: "",
    userInfo: {
      username: '',
      avatar: '',
    },
    routes:staticRoutes

  }),
  actions:{
    setToken(token: string) {
      this.token = token;
    },
    setUserInfo(userInfo: userInfoReponseData) {
      this.userInfo = userInfo;
    }
  },
  persist: piniaPersistConfig("xianda-user")
  
})

